package com.HW;


/**
 * @ClassName : TStrIntervalReverse
 * @Author : kele
 * @Date: 2023/10/24 22:31
 * @Description :按区间反转文章片段
 */
public class TStrIntervalReverse {

    public static void main(String[] args) {

        handle("I am a developer.", 0, 3);
        handle("I am a developer.", 1, 2);
        handle("Hello world!", 0, 1);
    }

    public static void handle(String str, int begin, int end) {

        String[] split = str.trim().split("\\s+");

        if (end > split.length - 1 || end < begin || begin < 0 || begin > split.length - 1) {
            System.out.println("EMPTY");
            return;
        }

        StringBuilder builder = new StringBuilder();

        for (int i = 0; i < begin; i++) {
            builder.append(split[i]).append(" ");
        }

        for (int i = end; i >= begin; i--) {
            builder.append(split[i]).append(" ");
        }

        if (end < split.length - 1) {
            for (int i = end + 1; i < split.length; i++) {
                builder.append(split[i]).append(" ");
            }
        }

        


        System.out.println(builder.substring(0, builder.length() - 1));

    }
}
